package ar.edu.utn.frba.dds.tp.code.vuelos;

import java.util.ArrayList;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterators;


public class BuscadorVuelos {
	
	private static final BuscadorVuelos INSTANCE = new BuscadorVuelos();
	private ArrayList<Aerolinea> aerolineas = new ArrayList<Aerolinea>(); 
	
	
	public ArrayList<Aerolinea> getAerolineas() {
		return aerolineas;
	}

	public static BuscadorVuelos getInstance() {
		return INSTANCE;
	}
	
	public void agregarAerolinea(final Aerolinea aero){
		
		if(Iterators.any(this.aerolineas.iterator(), new Predicate<Aerolinea>() {
		
			public boolean apply (Aerolinea unaAerolinea){
				return !(unaAerolinea.getClass().equals(aero.getClass()));
			}
		})
		)
		{
			this.aerolineas.add(aero);
		}
		if(this.aerolineas.isEmpty()){
			this.aerolineas.add(aero);
		}
	}
	
	public void sacarAerolinea(Aerolinea aero){
		this.aerolineas.remove(aero);
	}
	
	public void clearAerolineas(){
		this.aerolineas.clear();
	}
	
	public void buscar(Busqueda unaBusqueda){
		
		for (Aerolinea aero : this.aerolineas) {
			aero.handlerNuevaBusqueda(unaBusqueda);
		}
		
	}

}
